]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
shell: Use one-shot idle/timeout functions
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 31 Oct 2025 16:57:20 +0000 (17:57 +0100)
committerMarge Bot <marge-bot@gnome.org>
Thu, 29 Jan 2026 15:16:04 +0000 (15:16 +0000)
GLib added one-shot variants of the idle/timeout functions a while ago.

While they don't save a lot of code, they serve as a clear marker that
the callback is only invoked once.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3947>

src/shell-app-cache.c
src/shell-app-usage.c
src/shell-edge-drag-gesture.c
src/shell-perf-helper.c
src/shell-polkit-authentication-agent.c

index 484e0248c562295dec891dc4fd56a236cabf2b10..31c28fcb258ef3153e0c410cca79957e8573b515 100644 (file)
@@ -194,7 +194,7 @@ apply_update_cb (GObject      *object,
   cache_state_free (state);
 }
 
-static gboolean
+static void
 shell_app_cache_do_update (gpointer user_data)
 {
   ShellAppCache *cache = user_data;
@@ -213,8 +213,6 @@ shell_app_cache_do_update (gpointer user_data)
   task = g_task_new (cache, cache->cancellable, apply_update_cb, NULL);
   g_task_set_source_tag (task, shell_app_cache_do_update);
   g_task_run_in_thread (task, shell_app_cache_worker);
-
-  return G_SOURCE_REMOVE;
 }
 
 static void
@@ -225,9 +223,9 @@ shell_app_cache_queue_update (ShellAppCache *self)
   if (self->queued_update != 0)
     g_source_remove (self->queued_update);
 
-  self->queued_update = g_timeout_add_seconds (DEFAULT_TIMEOUT_SECONDS,
-                                               shell_app_cache_do_update,
-                                               self);
+  self->queued_update = g_timeout_add_seconds_once (DEFAULT_TIMEOUT_SECONDS,
+                                                    shell_app_cache_do_update,
+                                                    self);
 }
 
 static void
index 9e57a91b269b35b70ed45da8cb0b321e3fe6a604..a6edc271bd3c7d1a7c9ef2da98b6a400b89463e7 100644 (file)
@@ -108,7 +108,7 @@ static void on_session_status_changed (GDBusProxy *proxy, guint status, ShellApp
 static void on_focus_app_changed (ShellWindowTracker *tracker, GParamSpec *spec, ShellAppUsage *self);
 static void ensure_queued_save (ShellAppUsage *self);
 
-static gboolean idle_save_application_usage (gpointer data);
+static void idle_save_application_usage (gpointer data);
 
 static void restore_from_file (ShellAppUsage *self);
 
@@ -426,7 +426,8 @@ ensure_queued_save (ShellAppUsage *self)
 {
   if (self->save_id != 0)
     return;
-  self->save_id = g_timeout_add_seconds (SAVE_APPS_TIMEOUT_SECONDS, idle_save_application_usage, self);
+  self->save_id = g_timeout_add_seconds_once (SAVE_APPS_TIMEOUT_SECONDS,
+                                              idle_save_application_usage, self);
   g_source_set_name_by_id (self->save_id, "[gnome-shell] idle_save_application_usage");
 }
 
@@ -526,7 +527,7 @@ write_attribute_double (GDataOutputStream *stream,
 }
 
 /* Save app data lists to file */
-static gboolean
+static void
 idle_save_application_usage (gpointer data)
 {
   ShellAppUsage *self = SHELL_APP_USAGE (data);
@@ -546,7 +547,7 @@ idle_save_application_usage (gpointer data)
     {
       g_debug ("Could not save applications usage data: %s", error->message);
       g_error_free (error);
-      return FALSE;
+      return;
     }
   buffered_output = g_buffered_output_stream_new (G_OUTPUT_STREAM (output));
   g_object_unref (output);
@@ -594,7 +595,6 @@ out:
       g_debug ("Could not save applications usage data: %s", error->message);
       g_error_free (error);
     }
-  return FALSE;
 }
 
 static void
index f4f973299bb1e75956579ee1da55d76b4db7f18e..f2f4b65ffbf4251bdf11fdba5e0b5ba624aa801d 100644 (file)
@@ -127,7 +127,7 @@ exceeds_cancel_threshold (ShellEdgeDragGesture *self,
   clutter_gesture_get_point_coords_abs (CLUTTER_GESTURE (self),
                                         point,
                                         &latest_coords);
-  
+
   graphene_point_distance (&latest_coords, &begin_coords, &distance_x, &distance_y);
 
   switch (self->side)
@@ -194,7 +194,7 @@ shell_edge_drag_gesture_should_handle_sequence (ClutterGesture     *gesture,
   return FALSE;
 }
 
-static gboolean
+static void
 on_cancel_timeout (gpointer data)
 {
   ShellEdgeDragGesture *self = data;
@@ -203,7 +203,6 @@ on_cancel_timeout (gpointer data)
     clutter_gesture_set_state (CLUTTER_GESTURE (self), CLUTTER_GESTURE_STATE_CANCELLED);
 
   self->cancel_timeout_id = 0;
-  return G_SOURCE_REMOVE;
 }
 
 static void
@@ -223,7 +222,7 @@ shell_edge_drag_gesture_point_began (ClutterGesture *gesture,
   self->cancel_timeout_point = point;
 
   g_assert (self->cancel_timeout_id == 0);
-  self->cancel_timeout_id = g_timeout_add (CANCEL_TIMEOUT_MS, on_cancel_timeout, self);
+  self->cancel_timeout_id = g_timeout_add_once (CANCEL_TIMEOUT_MS, on_cancel_timeout, self);
 }
 
 static void
index db36e72133756958148044bb3430592482140b6f..613fc1cf1339e11f779df370fb342704c235d63e 100644 (file)
@@ -88,7 +88,7 @@ static void destroy_windows           (PerfHelperApp *app);
 static void finish_wait_windows       (PerfHelperApp *app);
 static void check_finish_wait_windows (PerfHelperApp *app);
 
-static gboolean
+static void
 on_timeout (gpointer data)
 {
   PerfHelperApp *app = data;
@@ -96,8 +96,6 @@ on_timeout (gpointer data)
 
   destroy_windows (app);
   g_application_quit (G_APPLICATION (app));
-
-  return FALSE;
 }
 
 static void
@@ -105,7 +103,7 @@ establish_timeout (PerfHelperApp *app)
 {
   g_clear_handle_id (&app->timeout_id, g_source_remove);
 
-  app->timeout_id = g_timeout_add (opt_idle_timeout * 1000, on_timeout, app);
+  app->timeout_id = g_timeout_add_once (opt_idle_timeout * 1000, on_timeout, app);
   g_source_set_name_by_id (app->timeout_id, "[gnome-shell] on_timeout");
 }
 
index 6815f01aff25185f19944f91938ea1da243e62de..62676bd121e4a42da6dce1e3bb21c39dafd396c9 100644 (file)
@@ -262,7 +262,7 @@ auth_request_initiate (AuthRequest *request)
 static void auth_request_complete (AuthRequest *request,
                                    gboolean     dismissed);
 
-static gboolean
+static void
 handle_cancelled_in_idle (gpointer user_data)
 {
   AuthRequest *request = user_data;
@@ -278,8 +278,6 @@ handle_cancelled_in_idle (gpointer user_data)
     {
       auth_request_complete (request, FALSE);
     }
-
-  return FALSE;
 }
 
 static void
@@ -293,7 +291,7 @@ on_request_cancelled (GCancellable *cancellable,
    *
    *  https://bugzilla.gnome.org/show_bug.cgi?id=642968
    */
-  id = g_idle_add (handle_cancelled_in_idle, request);
+  id = g_idle_add_once (handle_cancelled_in_idle, request);
   g_source_set_name_by_id (id, "[gnome-shell] handle_cancelled_in_idle");
 }